const wxPaymentApi = require('../weixin/payment');

const orderNotifyUrl = '/payment/creditOrderNotify';

// 下单
async function makeMchBill (orderId, openid, price) {
    orderId = orderId.toString();
    let notifyUrl = wxPaymentApi.getPaymentNotifyHost() + orderNotifyUrl;
    console.log('信用金还款下单：' + openid + ',' + notifyUrl);
    return wxPaymentApi.makeMehBill(orderId, orderId, price, openid, '信用金还款下单', notifyUrl);
}

// 下单回调
async function orderPaymentNotify (notifyData) {
    let xmlBuilder = wxPaymentApi.getXmlTool()[0];
    console.log('微信支付信用金回调成功：' + notifyData.xml.attach);
    return xmlBuilder.buildObject({
        return_code: 'SUCCESS',
        return_msg: 'OK'
    });
}

// 查询订单详情
async function orderHasPayed (orderId) {
    return wxPaymentApi.orderHasPayed(orderId);
}

module.exports = {
    makeMchBill,
    orderPaymentNotify,
    orderHasPayed
};
